import { ApiProperty, IntersectionType, PartialType } from '@nestjs/swagger'
import { IsInt, IsOptional, IsString, Min, MinLength } from 'class-validator'

import { PagerDto } from '~/common/dto/pager.dto'
import { CommonStatus } from '~/enums/common.enum'

export class PostSaveDto {
  @ApiProperty({ description: '岗位ID' })
  @IsInt()
  @Min(0)
  @IsOptional()
  id?: number

  @ApiProperty({ description: '岗位编码' })
  @IsString()
  @MinLength(1)
  code: string

  @ApiProperty({ description: '岗位名称' })
  @IsString()
  @MinLength(1)
  name: string

  @ApiProperty({ description: '显示顺序' })
  @IsInt()
  @Min(0)
  sort: number

  @ApiProperty({ description: '状态（0正常 1停用）', enum: CommonStatus })
  @IsInt()
  @IsOptional()
  status?: CommonStatus

  @ApiProperty({ description: '备注' })
  @IsString()
  @IsOptional()
  remark?: string
}

export class PostQueryDto extends IntersectionType(PagerDto, PartialType(PostSaveDto)) {}

export class PostSimpleDto {
  @ApiProperty({ description: '岗位ID' })
  id: number

  @ApiProperty({ description: '岗位名称' })
  name: string
}
